{% extends 'base.html' %}
{% block title %}
    <title>{{ title }}</title>
{% endblock %}
{% block content %}
    <div class="layui-card">
        <div class="layui-card-header">修改密码</div>
        <div class="layui-card-body" pad15="">

            <div class="layui-form" lay-filter="">
                <div class="layui-form-item">
                    <label class="layui-form-label">当前密码<i class="require_i">*</i></label>
                    <div class="layui-input-inline">
                        <input type="password" name="old_password" lay-verify="password" lay-vertype="tips"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">新密码<i class="require_i">*</i></label>
                    <div class="layui-input-inline">
                        <input type="password" name="password" lay-verify="password" lay-vertype="tips" autocomplete="off"
                               id="LAY_password" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">6到15个字符</div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">确认新密码<i class="require_i">*</i></label>
                    <div class="layui-input-inline">
                        <input type="password" name="repassword" lay-verify="password" lay-vertype="tips"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="setmypass">确认修改</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
{% block customjs %}
    <script src="/static/js/set_csrf_async.js"></script>
    <script>
        layui.use('form', function () {
            var layer = layui.layer;
            var form = layui.form;
            // 自定义表单验证
            form.verify({
                password: [/^[\S]{6,15}$/, '密码必须6到15位，且不能出现空格']
            });

            // 监听修改用户信息表单提交
            form.on('submit(setmypass)', function (data) {
                $.ajax({
                        type: 'post',
                        url: '/user/center/',
                        data: data.field,
                        dataType: 'json',
                        success: function (data) {
                            if (data.code === 0) {
                                layer.msg(data.msg, {
                                    icon: 6, time: 2000, end: function () {
                                        location.href = '/user/center/'
                                    }
                                });

                            } else {
                                layer.alert('Failed:' + data.msg);
                                return
                            }
                        }
                    }
                );
                return false;
            });
        })
        ;
    </script>
{% endblock %}